package com.yundasys.lab10designpattern.template;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * @PACKAGE_NAME: com.yundasys.lab10designpattern.template
 * @NAME: Main
 * @USER: jiangta
 * @DATE: 2021/8/26
 * @TIME: 3:39 下午
 * @PROJECT_NAME: springboot-labs
 */
public class Main {

    public static void main(String[] args) throws SQLException {
        String sql = "select * from User";
        JdbcTemplate jt = new JdbcTemplateUserImpl();
        List<User> userList = (List<User>) jt.execute(sql);


        JdbcTemplate2 jdbcTemplate2 = new JdbcTemplate2();
        jdbcTemplate2.query(new StatementCallback() {
            @Override
            public Object doInStatement(Statement stmt) throws SQLException {
                ResultSet rs = stmt.executeQuery(sql);
                List<User> userList = new ArrayList<User>();
                User user = null;
                while(rs.next()) {
                    user = new User();
                    user.setId(rs.getInt("id"));
                    user.setUserName(rs.getString("user_name"));
                    user.setBirth(rs.getDate("birth"));
                    user.setCreateDate(rs.getDate("create_date"));
                    userList.add(user);
                }

                return null;
            }
        });
    }
}
